﻿using UnityEngine;
using System.Collections.Generic;
using TTGame;
/*
 * AttackFrame
 *
 * AttackFrame可以手动添加DRCollider，也可以不加。DRCollider的参数在AttackFrame中设置。
 *
 * 结束条件：
 * 时间、碰撞次数
 *
 * 依赖：
 * puppet, DamageReceiverCollider, MagicBallManager
 *
 * ！不写重复代码！
 * @author TTun
 * @date 7/19/2017 8:59:17 AM
 */
namespace TTGameEngine {
public enum ColliderShape {
    Sphere,
    Rect,
    Sector,
    Line,
}



//法球 - 攻击框
//不会移动，坐标跟随玩家移动
public class AttackFrame : MagicBall {

    protected override void init(int skillID, uint castID) {
        base.init(skillID, castID);

        if(m_colInfo.m_targetType.IsID((int)TargetSelectType.Self)) {
            targetObjIsSelf = true;
        } else {
            LayerMask layerMask = ObjectManager.Share().GetObjLayerMask(m_colInfo.m_targetType, m_owner.m_objType);
            drCollider = GameExt.AddDRColliderComponent(m_colInfo, transform, gameObject, layerMask);
            drCollider.onColliderEnter += OnCollider;
            drCollider.OnHitObject += OnHitEffect;
        }
    }

    protected override void Update() {
        float dt = Time.deltaTime;
        bool result = true;
        result &= updateLife(dt);
        if(result) {
            result &= updateColliderCount();
        }

        if(result == false) {
            OnLifeOver();
        }
    }

    public void OnTimeOver() {
        DeactiveMagicBall();
    }

    public override void EmitSelf() {
        xform.parent = m_owner.BindObjsRootTF;
        xform.localPosition = Vector3.zero;
        //扇形碰撞检测时，需要获取人物面向。在此，保证AttackFrame的面向和人物面向一致。
        xform.localRotation = Quaternion.identity;
        base.EmitSelf();
    }

    public override void Fire() {
        base.Fire();
    }

    public override void DeactiveMagicBall(bool isRemove = true) {
        base.DeactiveMagicBall(isRemove);
    }

}

}